package cn.endeavour.sys.service.impl;

import cn.endeavour.basic.service.impl.BaseServiceImpl;
import cn.endeavour.sys.domain.SystemDictionaryType;
import cn.endeavour.sys.mapper.SystemDictionaryDetailMapper;
import cn.endeavour.sys.mapper.SystemDictionaryTypeMapper;
import cn.endeavour.sys.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ISystemDictionaryTypeServiceImpl extends BaseServiceImpl<SystemDictionaryType> implements ISystemDictionaryTypeService {
    @Autowired
    private SystemDictionaryDetailMapper mapper;

    @Autowired
    private SystemDictionaryTypeMapper typeMapper;

    @Override
    @Transactional
    public void delete(Long id) {
        // 直接删除明细表
        mapper.deleteType(id);
        // 删除类型
        super.delete(id);
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        // 批量删除明细
        mapper.patchDeleteType(ids);
        super.patchDelete(ids);
    }

    @Override
    @Transactional
    public void add(SystemDictionaryType systemDictionaryType) {
        // 先判断是否存在
        SystemDictionaryType type = typeMapper.findSn(systemDictionaryType.getSn());
        if (type != null) {
            throw new RuntimeException("编号不能重复哦!");
        } else {
            super.add(systemDictionaryType);
        }

    }
}
